<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>
        /**
         *   es6的let关键字
         **/

        //1.演示let的块作用域问题
        {
            let name = '二狗子'
            console.log(name);
        }
        //超出作用域 
        console.log(name);   

        //2.let不能重复声明
        let a = 1;
        let b = 2;
        //let a = 3;

        //3.let和var范围区别演示
        ///js单线程模型,如果循环包裹了定时任务,定时任务会在遍历结束后执行!
        for (var i = 0; i < 10; i++) {
            setTimeout(function(){
                console.log(i);
                //10个10
            })
        }
       console.log("-------------------")
        for (let j = 0; j < 10; j++) {
            setTimeout(function(){
                console.log(j);
                //0-9
            })
        }

        //4. let不会自动提升级别
        //识别到了hehe变量
        //var变量提升的能力
        console.log(hehe);
        var hehe = "哈哈";
        console.log(hehe);

        //let没有变量提升能力
        console.log(heihei);
        let heihei = "嘿嘿"
        console.log(heihei);
    </script>
</body>
</html>